//app.js
var login = require('./common/login')
var session = require('./common/session');
App({
  onLaunch: function () {
    // login.login();
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        var appid = 'wxca4cbb9297f42aaf'; //填写微信小程序appid 
        var secret = '52b2ff4170fb632b43064b146bcf5fa1'; //填写微信小程序secret 

        //调用request请求api转换登录凭证 
        wx.request({
          url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&grant_type=authorization_code&js_code=' + res.code,
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            //获取openid 
            // that.globalData.openid = res.data.openid;
            session.set('xyznzzopenId', res.data.openid)
          },
          fail: function (res) {
            console.log(res)
          }
        })
      }
    })
  }
})
